﻿using System;
using System.Reflection;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;

namespace Sinacor.Infra.Tools.ServiceGenerator.Exporter
{
    class Program
    {
        static void Main(string[] args)
        {
            try
            {
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Generating file . . .");

                string fileName = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) + "\\ServiceRegistration.txt";
                ServiceRegistration.Business.Module biz = new ServiceRegistration.Business.Module();
                StreamWriter file = new StreamWriter(fileName);
                StringBuilder line = null;

                DataSet ds = biz.SelectAll();

                if (ds != null && ds.Tables.Count > 0)
                {
                    foreach (DataRow dr in ds.Tables[0].Rows)
                    {
                        line = new StringBuilder();

                        line.Append(dr["NOME_MOD"].ToString().PadRight(51));
                        line.Append(dr["SIGL_MOD"].ToString().PadRight(5));

                        line.Append(dr["NOME_SUB_MOD"].ToString().PadRight(51));
                        line.Append(dr["NUM_PRTA_SERV"].ToString().PadRight(6));

                        line.Append(dr["NOME_SERV"].ToString().PadRight(51));
                        line.Append(dr["DESC_SERV"].ToString().PadRight(513));

                        line.Append(dr["NOME_MET_SERV"].ToString().PadRight(129));
                        line.Append(dr["DESC_MET_SERV"].ToString().PadRight(513));
                        line.Append(dr["NOME_TABL_UTI_MET"].ToString().PadRight(513));
                        line.Append(dr["IND_COLE_METODO"].ToString().PadRight(2));
                        line.Append(dr["NOME_NAMS_METODO"].ToString() + "." + dr["NOME_TIPO_METODO"].ToString().PadRight(513));
                        
                        line.Append(dr["NOME_PARM_MET"].ToString().PadRight(129));
                        line.Append(dr["DESC_PARM_MET"].ToString().PadRight(513));
                        line.Append(dr["IND_COLE_PARAMETRO"].ToString().PadRight(2));
                        line.Append(dr["NOME_NAMS_PARAMETRO"].ToString() + "." + dr["NOME_TIPO_PARAMETRO"].ToString().PadRight(513));

                        file.WriteLine(line.ToString());
                    }
                }

                file.Close();
            }
            catch (Exception ex)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine(ex.Message);
            }

            Console.ForegroundColor = ConsoleColor.White;
            Console.WriteLine(" ");
            Console.WriteLine("Press any key to continue . . .");
            Console.ResetColor();
            Console.ReadLine();
        }
    }
}
